package com.zzh.lib.views.utils;

import android.content.Context;
import android.util.TypedValue;

/**
 * 单位转换
 */
public class DimenUtil {
    /**
     * dip转换成px
     */
    public static int dp2px(Context context, float dipValue) {
        float scale = context.getApplicationContext().getResources().getDisplayMetrics().scaledDensity;
        return (int) (dipValue * scale + 0.5f);
    }

    /**
     * sp 转px
     *
     * @param spValue sp值
     * @return px
     */
    public static int sp2px(Context ctx, int spValue) {
        float pxValue = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spValue, ctx.getApplicationContext().getResources().getDisplayMetrics());
        return (int) (pxValue + 0.5f);
    }
}